<?php

declare(strict_types=1);

namespace App\Robot\Amqp\Consumer;


use App\Robot\Job\SendRecordMsgDelayedTaskJob;
use App\Robot\Service\QueueService;
use Hyperf\Amqp\Annotation\Consumer;
use Hyperf\Amqp\Message\ConsumerMessage;
use Hyperf\Amqp\Result;
use function Hyperf\Collection\data_get;

#[Consumer(exchange:"hyperf_exchange", routingKey:"hyperf_low_priority", queue:"hyperf_low_priority", name:"LowPriorityConsumer", nums:1)]
class LowPriorityRobotMsgConsumer extends ConsumerMessage
{
    public function consume($data): Result
    {
        // 判断是否需要延迟
        $delay = data_get($data,'delay',0);
        $messageData = data_get($data,'data',[]);
        $job = new SendRecordMsgDelayedTaskJob($messageData);
        stdout_log()->info("发送消息延迟时间 = ".$delay);
        container()->get(QueueService::class)->push($job,$delay);
        return Result::ACK;
    }

    public function isEnable(): bool
    {
        return \Hyperf\Support\env('AMQP_CONSUMER_ENABLE',false);
    }
}